package com.example.shopingcenter;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.MenuItem;

import com.example.shopingcenter.Fragment.FondFragment;
import com.example.shopingcenter.Fragment.HomeFragment;
import com.example.shopingcenter.Fragment.MineFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class MainAllFragActivity extends AppCompatActivity {
    List<Fragment> list;
    private BottomNavigationView botom;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_all_frag);


        if (Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

        botom = findViewById(R.id.bottomnavigation);

        list=new ArrayList<>();
        list.add(new HomeFragment());
        list.add(new FondFragment());
        list.add(new MineFragment());


        show(list.get(0));

        botom.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.navigation_home:
                        show(list.get(0));
                        break;
                    case R.id.menu_found:
                        show(list.get(1));
                        break;
                    case R.id.menu_me:
                        show(list.get(2));
                        break;

                }
                return true;
            }
        });

    }

    private void show(Fragment fragment){

        FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.framelayout,fragment);
        ft.commit();
    }

}